#include "Vertex.h"
#include "util/ByIdMatcher.h"

Vertex::Vertex(std::string id, double x, double y) {
	this->setId(id);
	this->setPositionX(x);
	this->setPositionY(y);
}

Vertex::~Vertex() {

}

bool Vertex::equals(Vertex* other) {
	ByIdMatcher<Vertex*> matcher(this);
	return matcher.matches(other);
}

std::string Vertex::getId() {
	return this->id;
}

double Vertex::getPositionX() {
	return this->position_x;
}

double Vertex::getPositionY() {
	return this->position_y;
}

void Vertex::setId(std::string id) {
	this->id = id;
}

void Vertex::setPositionX(double x) {
	this->position_x = x;
}

void Vertex::setPositionY(double y) {
	this->position_y = y;
}

Vertex* Vertex::addOutgoingEdge(Edge* edge) throw (DuplicateElementException) {
	ByIdMatcher<Edge*> matcher;
	if (this->outgoingEdges.contains(matcher.setCurrent(edge))) {
		throw(DuplicateElementException("El vertice \"" + this->getId()
				+ "\" ya contiene a la arista saliente \"" + edge->getId()
				+ "\"."));
	} else {
		this->outgoingEdges.append(edge);
	}
	return this;
}

util::LinkedList<Vertex::Edge*>* Vertex::getOutgoingEdges() {
	return &(this->outgoingEdges);
}
